<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
<!--
                <el-breadcrumb-item><i class="el-icon-menu"></i> 表格</el-breadcrumb-item>
-->
                <el-breadcrumb-item>积分项列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>

        <div class="handle-box">
             <el-dialog :title="title" :visible.sync="dialogFormVisible">
             <el-form ref="form" :model="form" label-width="80px">

                 <el-form-item label="编码">
                    <el-col :span="10">
                        <el-input maxlength="10" v-model="form.code" class="handle-input" v-bind:disabled="is_show==false"></el-input>
                   </el-col>
                    <el-col class="line" :span="4">人员类别</el-col>
                    <el-col :span="10">
                      <el-select v-model="form.scoreType" placeholder="请选择.." class="handle-select mr10" v-bind:disabled="is_show==false">
                            <el-option
                                    v-for="item in scoreTypeList"
                                    :key="item.code"
                                    :label="item.name"
                                    :value="item.code">
                            </el-option>
                    </el-select>
                </el-col>
                </el-form-item>

                   <el-form-item label="积分类别">
                    <el-col :span="11">
                      <el-select v-model="form.category" placeholder="请选择.." class="handle-select mr10" v-bind:disabled="is_show==false">
                            <el-option
                                    v-for="item in categoryList"
                                    :key="item.code"
                                    :label="item.name"
                                    :value="item.code">
                            </el-option>
                    </el-select>
                </el-col>
                <el-col class="line" :span="2">分值</el-col>
              <el-col :span="11">
                    <el-input-number  v-model="form.score" @change="handleChange" :min="1" :max="100" v-bind:disabled="is_show==false"></el-input-number>
                </el-col>
            </el-form-item>
                <el-form-item label="结果设定">
                    <el-input maxlength="200" v-model="form.result" type="textarea" placeholder="请输入内容" v-bind:disabled="is_show==false"></el-input>
                </el-form-item>
                <el-form-item label="工作详情">
                   <el-input  maxlength="200" type="textarea" :rows="2"  placeholder="请输入内容"
                               v-model="form.detail" v-bind:disabled="is_show==false"> </el-input>
                </el-form-item>

                <el-form-item label="备注">

                    <el-input maxlength="200" type="textarea" :rows="2"  placeholder="请输入内容"
                               v-model="form.remark" v-bind:disabled="is_show==false"> </el-input>

                </el-form-item>

                <el-form-item>
                    <el-button type="primary" v-if="is_show" @click="onSubmit">提交</el-button>
                    <el-button v-if="is_show" @click="cancel">取消</el-button>
                    <el-button v-if="is_show==false" @click="cancel">关闭</el-button>
                </el-form-item>
            </el-form>
            </el-dialog>

            <el-button type="primary" icon="edit" class="handle-del mr10"  @click="save()">新增</el-button>
        </div>
        <div class="handle-box">

            <el-input v-model="code" clearable placeholder="编码" class="handle-input mr10" icon="circle-close" :on-icon-click="handleIconClick"></el-input>
            <el-select v-model="category" clearable placeholder="积分类别" class="handle-select mr10">
                         <el-option
                                    v-for="item in categoryList"
                                    :key="item.code"
                                    :label="item.name"
                                    :value="item.code">
                            </el-option>
                    </el-select>
             <el-select v-model="scoreType" clearable placeholder="人员类别" class="handle-select mr10">
                 <el-option
                            v-for="item in scoreTypeList"
                            :key="item.code"
                            :label="item.name"
                            :value="item.code">
                    </el-option>
            </el-select>
            <el-button type="primary" icon="search" @click="search">搜索</el-button>
        </div>
        <el-table :data="data" border style="width: 100%" ref="multipleTable" @selection-change="handleSelectionChange">
           <!-- <el-table-column type="selection" width="55"></el-table-column>-->
           <el-table-column v-if="false"  prop="id" label="departmentId"  width="150">
            </el-table-column>
            <el-table-column  prop="code" label="编码"  style="width: 40%">
                <template slot-scope='scope'>
                <a style="border-bottom:solid 1px; cursor: pointer"  @click="detailed(scope.$index, scope.row)"> {{scope.row.code}}</a>
                </template>
            </el-table-column>


            <el-table-column prop="score" label="分值" style="width: 40%">
            </el-table-column>


             <el-table-column label="操作" width="width: 20%">
                <template slot-scope="scope">
                    <el-button size="small"
                            @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                             <el-button size="small" type="danger"
                            @click="handleDelete(scope.$index, scope.row)">删除</el-button>

                </template>
            </el-table-column>
        </el-table>
        <div class="pagination">
            <el-pagination
                    @current-change ="handleCurrentChange"
                    @size-change="handleSizeChange"
                    layout="sizes,prev, pager, next, total"
                    :page-sizes="[10,20,50]"
                    :page-size="pageSize"
                    :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                url: './static/vuetable.json',
                tableData: [],
                curPage: 1,
                pageSize: 10,
                total:0,
                title:'',
                multipleSelection: [],
                code: '',
                del_list: [],
                departmentCode:'',
                category:'',
                superiorDepartmentCode:'',
                scoreType:'',
                departmentList:'',
                dialogFormVisible: false,
                categoryList:[
                 {name:'配合组长工作',code:'A'},
                 {name:'客户满意度',code:'B'},
                 {name:'公司流程',code:'C'},
                 {name:'培训',code:'D'},
                 {name:'公司活动',code:'E'}
                ],
                scoreTypeList:[
                 {name:'组长',code:'TL'},
                 {name:'组员',code:'TM'}
                ],
                form: {
                    id: null,
                    code:'',
                    scoreType:'',
                    category:'',
                    score: '',
                    result: '',
                    detail: '',
                    remark: ''
                },
                is_search: false,
                is_show:false
            }
        },
        created(){
            this.getData();
        },
        computed: {
            data(){
                const self = this;
                return self.tableData.filter(function(d){

                    let is_del = false;
                    for (let i = 0; i < self.del_list.length; i++) {

                        if(d.name === self.del_list[i].name){
                            is_del = true;
                            break;
                        }
                    }
                    return d;
                })
            },
            totalRecord(){
                return this;
            }
        },
        methods: {
            handleCurrentChange(val){
                this.curPage = val;
                this.getData();
            },
             handleSizeChange (val) {
                 this.pageSize = val;
                 this.getData();

           } ,
            getData(){
                let self = this;
                if(process.env.NODE_ENV === 'development'){
                    self.url = '/ms/table/list';
                };
               var searchCriteria = {};
               searchCriteria.code = self.code;
               searchCriteria.scoreType = self.scoreType;
               searchCriteria.category = self.category;

                self.$axios.post("../adm/performanceScore/page?size="+self.pageSize+"&page="+(self.curPage-1), searchCriteria).then((res) => {
                    self.tableData = res.data;
                    self.total = res.total;

                });



            },
            handleDelete(index, row) {
             let self = this;
              self.$axios.get('../adm/performanceScore/delete?id='+row.id, {page:self.curPage}).then((res) => {
              self.getData();
                this.$message.error('删除成功！');

                  })

            },
            save() {
                let self = this;
                self.title = '新增项'
                self.dialogFormVisible = true ;
                self.form.code = '';
                self.form.id = '';
                self.form.scoreType = '';
                self.form.score = '';
                self.form.result = '';
                self.form.detail = '';
                self.form.remark = '';
                self.form.category = '';
                self.is_show = true;
            },
             cancel() {
                let self = this;
                self.dialogFormVisible = false ;

            },
            onSubmit() {

                var self = this;

                 if(!self.form.code){
                     this.$message.error('code不可为空');
                     return;
                }
                  if(!self.form.score){
                     this.$message.error('分数不可为空');
                     return;
                }
                   if(!self.form.scoreType){
                     this.$message.error('类别不可为空');
                     return;
                }

                self.$axios({
                    method: 'post',
                    url: '../adm/performanceScore/save',
                    handleAs:"json",
                    headers:{'Content-Type':'application/json'},
                    data: JSON.stringify(self.form)

                }).then(function (res) {

                     self.dialogFormVisible = false ;
                     self.$message.success('操作成功！');
                     self.getData();

                }).catch(function (err) {
                })

          },
            search(){

               let self = this;
               var searchCriteria = {};
               searchCriteria.code = self.code;
               searchCriteria.scoreType = self.scoreType;
                searchCriteria.category = self.category;
               self.$axios.post("../adm/performanceScore/page?size="+self.pageSize+"&page="+(self.curPage-1), searchCriteria).then((res) => {
                    self.tableData = res.data;
                    self.total = res.total;

                });

            },
            handleIconClick(){
                let self = this;
                this.code = "";
            },
            formatter(row, column) {
                return row.name;
            },
            filterTag(value, row) {
                return row.tag === value;
            },
            detailed(index, row) {
                let self = this;
                self.title = '积分明细'
                self.dialogFormVisible = true;
                self.is_show = false;
                self.$axios.get('../adm/performanceScore/detail?id='+row.id, {page:self.curPage}).then((res) => {
                self.form = res.data;
                })
            },
             handleEdit(index, row) {
                let self = this;
                self.title = '编辑积分'
                self.dialogFormVisible = true;
                self.is_show = true;
                self.$axios.get('../adm/performanceScore/detail?id='+row.id, {page:self.curPage}).then((res) => {
                self.form = res.data;
                  })
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            }
        }
    }
</script>

<style scoped>
.handle-box{
    margin-bottom: 20px;
}
.handle-select{
    width: 180px;
}
.handle-input{
    width: 180px;
    display: inline-block;
}
.input{
    width: 60px;
    display: inline-block;
}
.input1{
    width: 120px;
    display: inline-block;
}
.input2{
    width: 120px;
    display: inline-block;
    height: 100px;
}
</style>
